<template>
    <div class="update">
        <van-cell-group>
            <van-field v-model="phone" clearable label="手机号" placeholder="请输入手机号" />
        </van-cell-group>
        <van-cell-group>
            <van-field type="password" v-model="password" clearable label="密码" placeholder="请输入密码" />
        </van-cell-group>
        <!-- btn -->
        <van-button type="primary" size="large" class="save" @click="login">登录</van-button>
    </div>
</template>

<script>
import { apiLogin } from '../../api/index'
export default {
    data() {
        return {
            phone: '',
            password: ''
        }
    },
    methods: {
        login() {
            apiLogin(this.phone, this.password)
            .then(res => {
                var res = res.data.data.result
                if (res != 0) {
                    this.$store.state.user = res
                    this.$store.state.logging = 1
                    this.$router.push({path: '/user'})
                    localStorage.setItem('logging', JSON.stringify({id: res.id}))
                }
            })
            .catch(err => {
                console.log(err);
            })
        }
    }
}
</script>

<style lang="less" scoped>

</style>
